package com.ruoyi.service.impl;

import com.ruoyi.domain.*;
import com.ruoyi.dto.BasisLoadingUavCamp;
import com.ruoyi.framework.web.service.OnlineUserService;
import com.ruoyi.mapper.*;
import com.ruoyi.service.WordService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class WordServiceImpl implements WordService {

    @Autowired
    private BasisCaseLoadingMapper basisCaseLoadingMapper;

    @Autowired
    private BasisPositionMapper basisPositionMapper;

    @Autowired
    private BasisUavMapper basisUavMapper;

    @Autowired
    private UserDataMapper userDataMapper;

    @Autowired
    private BasisEquipmentInformationvMapper basisEquipmentInformationvMapper;

    @Autowired
    private BasisCaseLoadingTaskMapper basisCaseLoadingTaskMapper;

    @Autowired
    private SummaryContentMapper summaryContentMapper;

    @Autowired
    private ScoreMapper scoreMapper;

    @Autowired
    private  CommanderGradeMapper commanderGradeMapper;



    @Override
    public Map<String, Object> findPosition(String id) {

        Map<String, Object> map = new HashMap<>();


        BasisCaseLoading basisCaseLoading = basisCaseLoadingMapper.selectBasisCaseLoadingById(id);

        SummaryContent summaryContent =  summaryContentMapper.getSummary(id);
        map.put("loadingParam", basisCaseLoading);
        //演训总结
        map.put("summaryContent",summaryContent.getContent());
        //有几个阵地
        map.put("posionSum",scoreMapper.getPosSum(id));
        List<BasisCaseLoadingTask> tasks = basisCaseLoadingTaskMapper.findByCaseLoadingId(basisCaseLoading.getId());

        map.put("taskParam", tasks);
        //有多少人
        map.put("person",commanderGradeMapper.getSumPerson(id));
        //案例ID 获取成绩 和阵地名称
       List<Score> list = scoreMapper.getScoreList(id);
       List<ScoreAndPos> scoreAndPosList = new ArrayList<>();
       if (CollectionUtils.isNotEmpty(list)){
           for (Score score:list){
               ScoreAndPos scoreAndPos = new ScoreAndPos();
               scoreAndPos.setSumScore(score.getSumScore());
               //根据阵营ID查询 阵营名称
               BasisPosition basisPosition =  basisPositionMapper.findbyId(score.getPositionId());
               scoreAndPos.setPosName(basisPosition.getPositionName());
               scoreAndPosList.add(scoreAndPos);
           }
       }
        map.put("scoreAndPos",scoreAndPosList);


        //根据案例id和阵营id 查询对应的阵地
        List<BasisPosition> basisPositions = basisPositionMapper.findByLoadingIdAndCampId(basisCaseLoading.getId(), "1");
        map.put("BasisPositionParam", basisPositions);


        ArrayList<BasisEquipmentInformationv> basisEquipmentInformationvs = new ArrayList<>();
        ArrayList<UserData> userDataList = new ArrayList<>();

        for (BasisPosition basisPosition : basisPositions) {
            List<BasisEquipmentInformationv> equipmentInformationvs = basisEquipmentInformationvMapper.findByPositionIdType(Math.toIntExact(basisPosition.getId()), basisCaseLoading.getId());
            basisEquipmentInformationvs.addAll(equipmentInformationvs);


            List<UserData> userDatas = userDataMapper.findByPositionId(basisPosition.getId(), basisCaseLoading.getId());
            userDataList.addAll(userDatas);
        }
        map.put("BasisEquipmentInformationvParam", basisEquipmentInformationvs);
        map.put("UserDataParam", userDataList);



//        List<BasisLoadingUavCamp> byLoadingIdAndCampId = basisUavMapper.findByLoadingIdAndCampId(basisCaseLoading.getId(), 2);
//
//        map.put("uavParam", byLoadingIdAndCampId);


        return map;

    }
}
